cleaned code and fixed tests