Reorganize code, add more comments and update README.