Reduced the number of dict.get() calls.
Minor optimizations and cleanup