corrected a bug making the process slower