cleaned up and added test cases