Fixing some bugs and restructuring some predication code