debug mode and bug fix