fixing defect when leaving and improving logs when on debug mode