Fix some memory leaks and makes $* more efficient.