clean up emr code a bit