Finished implementation of functions