Patches for the 2 issues that I requested

Hello Martijn,

Here are the patches for the 2 issues and one of its related one, for you to review and merge (if you think they are good).

Cheers,
Anto