Clean up function a little