move redundant code to utils