Fixed #81 and #89

I improved my work from yesterday to fix new issues. I didn't build the sources to avoid unecessary merge conflict because another PR is open.

Feel free to ask me to rebase/build before merging this one.