Refactored code into a separate workers directory for webworker.