Some small changes and work on threads part.