Wrote all the functions but they are untested