made variable names more conventional, tidied up comments, and added casting to TPCircularBuffer to quiet the compiler.