Can you provide some more comments in the code for what you are doing and why? It's hard to follow.