use exceptions, register constants for flags