wrote functions, need debugging