Encapsulated some duplicate code.