solving threading problems, will clear the comments later