refactor and threads!