WIP: fix bug of pre-mature cleanup of capabilities