Cleaned up source, added multithreading