Move patch applying code to view