bug fix and error throw