First attempt at solution for programming assignment 2.