refactor. Added few tests