tried some refactoring, still not working