Added optional debug mode