I haven't run the code, but just reading through it I feel like this conditional needs to be inverted.