Refactor script to make it work better with solr