Rearranged some things and added more output statements.