Added fix to correctly handle switching to previous buffer