simplify the code somewhat