Added a check for wrong stream input. If stream is wrong then exception is thrown.