Fixing broken code, removing spaces from query