Added Test project to work with visual studio. Fixed a couple of bugs that tests found.