refactored sql
merged into _ratiofix.py
merging