Complete refactoring from SafeBox.