get rid of copy and paste horror: outsource some code of getLower/getUpper in helper function