added checking for valid form