Large improvements in assignment 2, part 1