Source code rewrite.

The old code works fine, but it's so unreadable and hard to document. Then, I decided to do it again! :D