Fixed includes and defines, refactored errors.