Begining work on multi threading

This is not finished yet.