This is basically sexy 2. I made a lot of things much simpler and added many more comments. This version is worth building off of.