Javascript works perfectly. Maybe I need to use multithreading?