APM: merged latest changes from Andrew Chapman