Trimming modified query instead of removing the last character