refactor WIP and added unit tests