Make code more robust and cross platform