Cleaned up the debug statements and added some comments.