cleanup, rearraging functions