Fixed Linux build and better error handling