unit test added, code cleanup and code formatting