Class exersize based on code from Stanford Homework