code cleanup
fixed tests and more cleanup