fix for SQL error and making at_least a parameter
fix for SQL error and making at_least a parameter