Made preprocessing more efficient