changed dictionary to be set and cleaned up code