Clean up code as per Chris's comments