Refactor action handling