Added a flush method to write the remaining bits into the byte stream

forgot to commit the place where the flush is actually called