simplify code a bit; better use of memory