Refactor out code to a block manager app state, plus minor overall improvements