Fixing memory corruption and a few comments