Refactoring and added Unit Tests.