Fixed and cleaned up the dialogue  code