[#50] Further refactoring
[#50] Refactoring and fix tests