Cleaned up the special cases for the g command and made it easier to add new ones.