this is the final version of the functions