added code from gui branch