Misc refactoring.
Weighted range refactoring.
Cleanup.
Reorganized files for better separation of interface and details.