fixed free corruption bug. Trying to speed up things now...