Cleaning and improving many of the common code snippets