Fixing bugs in policy generator. Still incomplete.