Rewrite to improve code readability.
Prepare for release 1.2