Refactor, added more tests