Refactoring and couple of tests