Removed s.close() and made a few changes