using std methods and cleaned up stuff in tools
fixed broken memory management