Factorize some code.
remove debug messages.
remove debug messages.
Minor indentation fix.