various cleanup
split some code from apply form into new class