Master cleanup

Updated deprecated and outdated code to current 2.x master - and stumbled upon a bug in the process.