Major cleanup.  Set up important event handlers and allow action element ids to be passed in.