Code cleanup, esp. poor boolean handling