I've fixed the bugs detailed in the diff. One of the bugs was already fixed on the local file (forgot to commit).