Final version of the functions