added set rule function. Also, applied some changes from master branch