Solution to Programming Assignment 2. Hope it works ;)