move redundant code to a separate file