Refactored for threading, consolidated files