replaced assertions with K exceptions
Merge pull request #1097 from yilongli/fixing-issue-1088

replaced some assertions with K exceptions