Code: Bug fixes and minor refactoring.
Merge pull request #25 from am11/master

Code: Bug fixes and minor refactoring