Fixed flag setting error and tested GUI (commented)