Added a close() function. This should take care of the errors due to the crusor