Re-wrote gui handling.

Gates basically done.