refactored, updated tests