needs refactoring