Moved some BPM functionality out of database and into BPM