Refactor and add epoll support.