formatted code ,fix bugs