got rid of unnecessary list and fixed if condition to use dictionary