added threading support and structure to code base.