Fixed sql (in model User), added null protection