Fixed it to work with proper threading