Cleaning up a code snippet