overhaul nearly done, code cleaned up, memory leaks fixed