Improved the accept_forever function