Some code cleaning. Added debug support.