Code

updated copy from 0.46 branch