Refactored some preprocessing