added context switches and various fixes