Refactoring some validation and action logic