JavaScript map behaviour fix