Cleaned up code and updated/reorganized tests