Gd fixes

I just realised that I forgot to send a pull request for the new branch, sorry about that. These are the same changes, but cleaned up.