Fixed entity functions not cleaning up variables.