Moved the unwrapping of nnParams into theta to a function.