Remove macro madness
Less defines
Make this static
Extract error reporting