Added const where needed
Improved debug output