There should be a way to write this that doesn't double-allocate. :(