refactoring, but still not working