Modernized, cleaned up, added some simple tests