Added missing checks for invalid values before trying to store them in DB.