get rid of some duplicate code