Added thread forking. Needs testing.