implementation of the function