added form validation. cleaned up the code.