Well, the first code I posted worked fine for me, I can't figure out what would have caused the problems some of you are having with it... But the post I made before has been edited with a shorter code that's easier to understand... so that might help with some of the problems. So far I haven't had any problems with it. I also tested it with the components on the right and left sides, as I've seen some people posted that it messed up if you had components on the left side.
If you're still having problems with the new code, let me know and we'll try to figure it out.