added tests and refactored them