correcting all errors, and prove that all functions are correct