Use bit field for flags
WIP on error handling [skip ci]