add more linebreaks, replace SQL LIMIT with param

@MTGap this just adds linebreaks to increase readability and replaces the last occurence of LIMIT with a parameter. please test.