add few tests && some refactoring