Fix error handling, add some more #define-flags-as-consts