major changes, fix exit problem