updated to work correctly for threading