added checkout function, and code formatting