Major rearrangement of source to make importable library for simple installation.