Improved: handle empty lists