changed the mode function