added some data validation and updated to fit database

also formatted code