Commented

Added various comments
Reorganized debug functions