Formatted the code and added notes