cleanup
tests and bug fix