Rewrite

Rewrite the whole code.