More cleanups and expose more megahal API