Merged Luke and Marvin's code