Some basic logic might be able to handle this.