Completed the code for all the functions, havent fully tested yet