Fix NoneType bug