Extract StagingApi and apply coolo's patches into this code