Some optimizations done after applying stuff from chapter 9 of The Ruby Programming Language