Fixed some memory leaks, improved and cleaned the software