Code written during session 2. Cleaned up and documented afterwards.