Better handling of threading