Add few tests, code refactored