refactored and added more tests