clean up, added functional helpers, extended threading