fixing problems that we did not know existed earlier

also preparing for a port ot windows.