cleaned some duplicate code up