Add some doc and reorganize source code to be a bit more readable at a first glance.