reverse + some refactoring