Fix the order of actions, fixes #520