functionize
refine sql query
money based bsd analysis