finished fixing the mapping function