build: many small code clean ups and fixes