Refactorated code in Toolbarpanel