tests added, code refactored