Fixed NPE and prepared for GUI stuff.