Clean up and add more unit tests