* drop unnec casts * reduce scope * tidy logic * boolify * tweak #include guards * add missing mxapi functions