Improve sign handling with better data structure.

Using a dictionary instead of a list clarifies the code.