Refactoring some confusing code, and adding an error when splicing
fails.