Fixed SQL bugs with adding decision checks