Added validation code & corrected some javascript code