Lab 5 - Final code for 5.1 and 5.2