added comments, formatting, and made returns explicit