cleaned code, added tests