added more tests and fixed some legacy code