clean up code and add test