Code cleanup and refactoring to remove extraneous references