Fix bugs uncovered by service/functional tests
squash
formatting (squash)