Added additional tests and refactored code.