removed code duplication.