Switched data structure to use dictionary instead of array for replacement