ensure sockets are always closed
remove all use of the % operator