Clean up and add tests