Consolidated some redundant code into a method.