First version of the function