Improved version with debug and one section option. Refactored code.