use wstring
provide better error messages in case of failure and properly cleanup after ourselfs
improve readability