fix function closing error