added comments and moved the main proceedure up to the top of the class.