M2 code cleanups