Many bug fixes.
Merge pull request #4 from a64adam/master

Updated files