Tidy up code, only add close event handler on relevant controls