managed to refactor