Cleaned up code and added some form validation