Fixed type checking and sanitized input