add tests, remove redundant code