reformat and adding debugging