Removes some duplicated code.