code cleanup and bug fixes in Emulink