Reduce code duplication based on Steve's feedback