Code cleanup, need to add class and threads