Move preprocessing stuff to a method