ack! 20 lines of logic replacing 2 lines of hash lookups...