optimize and format code