Error handling to the main code added.