refactored swapping into its own module