Fixing typo on contains vs containsKey and refactored to enable future unit testing