Completed Code (pre-testing)