Refactored the toolbox action logic