Fixed a few logic mistakes in the code
Merge pull request #9 from Subv/misc

Fixed a few logic mistakes in the code