Change module optimization to be whole project rather than per-module

Credit @orourkedd. Fixes #164.