clean up the function a bit