Cleaner way to handle out of range and swaps