changed the definition of insertAt