code refactor, emr interface in progress