Edited code as per HW6 P1 Requirements