Modified the code and made some format changes for the final submission.