refactored preprocessing