Added form validation. Some code cleanup.