Refactored submit handler, some JS tweaks