Fix a small bug. I should do some profiling too see if I can speed up the application, especially where multithreading is concerned