added more comparisons, semi-fixed handling of nil