new function handle-action, a bit more compact code