Refactor custom form and fix some bug