Implemented global buffer. Misc bugs