remove some duplicate code