added threading to intensive functions