refactory debug mode