todo: multi-thread support needed