Refactor, fixes for libuv changes