Final version w/ comments and indentation