Finally managed to implement validation after fixing some errors.