Code clean-ups and makefile optimizations