fix 'debug debug', change algorithm