Rebase of the stmt prepared statements branch

Rebased the stmt branch onto current master. Haven't tested it yet, just got it compiling cleanly.