generalized code a little more