Finished functions, still have a few small bugs to fix