fixed A LOT of errors, improved memory usage, got rid of a few memory leaks