Working pre-assignment 2 code