Reimplemented ACL generation to avoid quadratic complexity.