Added a test and cleaned up loose ends