tidying up the code, removed trailing whitespace etc.
bug fix related to the calculation of the necessary new blocks after the cached ones