Remove debug function and fix if's