some php fixes and sanitization of input values