Removed unnecessary error check and added a flush method