Added threading to drastically improve performance