Refactor dictionary for better performance and complete test