Function interface change: shared_ptr for C++11, safety and to allow copying

This allows Functions to be copied and makes it completely clear how the
memory is managed.