Cleanup and test fix
new tests and bug fixes