fixed tests and cleaned code