added order param, fixed database weighting