using @pv's suggestion for more speed