reduced duplicate code.