updated some functions to port it to windows.