Fix variable scope

Changed scope of preferences variables from global to buffer.