Added logic for CLI. Fixed a bug. Added methods in GUI.