Deep copy functions when cloning objects (cc#2050)

Based on pull #133. Fixes [CC#2050](http://issue.cc/r3/2050). Tested in Linux (0.4.4).