Implemented reference class to gui and some refactoring.