Simplifying programming Assignment 3