commented debug output, moved some code. No functional changes.