finished work on closePlugin function