Prepared command integration & a bit of refactoring