bug fixing and refactoring. Seems to be bug free.
fixing bugs and memory leaks
fixed another leak