Removed the uneven error-checking code to prepare for exception handling, and added comments before functions.