cleaned replacement function and organised scripts