fixing the close button and removing the redundant code