added unittest, refactor to class