Total rework of function necessary