fixed all issues and added unit test