Fixed bug where wrong (old) buffer variable was used (thanks clemens)