Added better state checking validation. Removed crummy JS validation.