Changes to improve performance using tanjamuse's library

This isn't a "real" pull request, but is instead the changes discussed in http://www.mobileread.com/forums/showthread.php?t=248762