needs refactor