Code optimization. Added debug output