Finish writing the basic functionality

The basic functionality has been finished. But it is not yet fully
debugged.