completed code for the three functions