Use subdirectory project for building.
Fixed thread problems.
Fixed nullptr bug.