Removed an expensive copy at the cost of slightly uglier code.