Optimize: replaced booleans with a flagset