Cleaning and splitting into modules.
Updated docs.