Bugfixes.

Fixes for issues: #97, #87 and other minor bugs.

P.S: I actually don't know how to remove that pull request I made to upload my fork. Please take it into account when merging.