more optimizations and buffered input stream added