Solution behind a card trick?

I just saw a new card trick tonight and I'm sure there's a mathematical solution to it....just wondering if anyone out there has seen it before. The trick goes like this:

1. Start with a 52-deck of cards

2. Flip the first card over; the number value of the card is the number that you "start counting with", and you count out the number of cards after that so that you end at 13. (For example, the first card you flip is a 9-card...you count out 4 more cards to "count" to 13...the proceeding 4 accounting for 10, 11, 12, and 13....and ultimately you have a little pile of 5 cards). When you are done counting that pile of cards, you put that pile - face down - aside.

3. Continue this process until the entire deck is in little piles of cards....however many it takes.

4. Pick up all but 3 piles of cards, so that all you have left are 3 face-down piles of cards. Flip the top card on any 2 of the piles.

5. Add the values of the 2 newly-flipped cards, and add 10.

6. In the remaining pile (the rest of the deck of cards that you picked up in step 4), count out the number of cards that you ended up with in step 5 - the sum of the values of the 2 cards that you flipped up plus 10.

7. The number of cards remaining in your hand are the same as the value of the "3rd" pile card that is still facing down. (So, for example, if in step 6 you have a 3 and a 5 facing up - you will have counted out 18 cards, and if you have 7 cards remaining in your hand, you can expect that last card to be a 7).

....VERY cool trick. Has anyone seen it and does anyone know why that works? I'm assuming that the magic number 13 relates somehow to the number of cards for a particular suit in the deck....or maybe, alternatively, it's based on the number 4 and 13 is the divisor that gets you there. :)

I'm sure this one will be swimming around in my head for awhile and I'm anxious to understand the answer...just pretty rusty in actually applying math, and off the bat if this has anything to do with linear algebra (which I know a lot of game theory is based on), I've never been overly strong in that area.

Any thoughts?