Tidied up the code somewhat. Its still having debugger problems under windows.