Reworked remap function