more refactoring, added validations, updated tests