Added more validation to javascript