Edited Lab 5, minor code re-arrangement