Cleaned up EMM detection code