updated linearize function