dynamic memory freed, small code changes