Reapply from master branch (cleaning up build system)