Fix build and minor refactor