Fixing AttributeError message (was always NoneType)