removing a bunch of unecessary stuffs.  Just check if the buffer is active before trying to do stuff on it.