Added unit testing. Fixed bugs concerning unit testing.