Fix nonetype error