Added and fixed validation code.