This is a complete function

Additional comments have been added to explain what the functions do