refactor code for get_action