improving the function