add tests and code clean up wip