cleanup and refactoring for easier multi-arch building