Shortened and simplified Udacity implementation