Fix some bugs and add better Linux support