[fix] Use `splice` to remove a middleware layer and fix the `indexOfLayer` method