created unit tests and refatored Code