Refactory emaf code.