preparing for merge. refactored sql for lexx