Fixed a bug in G matrix