simplify logic in various functions, remove unnecessary variables