simplify code as suggested by lslezak