refactored with HashWithIndifferentAccess and rename some variables