Big refactoring, add main, make brew doctor happy.