Cleaned up context switching.
Fixed pointer initialization.