Removed the last gc() calls left. Thus complying with the recommendation from http://adv-r.had.co.nz/memory.html that no gc() calls should be made as it's not really beneficial. Left rm() calls whenever there are still other calculations steps to go before the end of the function. That is, removed rm() calls just before a return() call.