fix buffering

optimize some methods
added twice foreach tests
fixes for added tests