Remove duplicate code for initializing an object for a form