Stream buffer time calc and some code rewrites