Reformatted most of the code, to improve readability. Eliminated some redundant print statements.