compressed a couple if statements, made the clear_buffer sub global