minor optimizations per suggestion on codereview