Numerious Bugfixes

Expanded test cases and fixed bugs