Cleaned up some code and made circular buffers and associated arrays volatile.