Improved background process design based on repeatWhileBlock