cleaned up and wrote tests for existing functionality