Slight cleanup and more efficient order of checking conditions.