fixed a bug in compile_sgs