Fixed some bugs.
Still a lot to fix.
Merge pull request #20 from stbnps/master

Fixed some bugs.