Remove garbage from end of query
Switch to new API and use query from separate file