Clean up code
Add tests