a lot of reorganizing for proper error handling. the clear threading and interfacing debugged and restructured. There is still a race in clear()