Improve gorenstein code.

This could be cleaned up a bit, but it seems to be a huge improvement for now.