Resolved some minor bugs and removed some memory leaks