Bugfix on buffer optimization

The previous patch added catching of OutOfMemoryError and returning null, but this wasn't always handled well.