begin refactor
Refactor, added tests