ajax enabled form; mostly works but needs refactoring