wrote the functions, added comments