Improve comments and include debug functions
Add debug code
Add debug config option