Fix bug where function result not applied to scope