update code for more general