Update for  issue #163 and #162
Conflicts removed by @Taitalus