More work on fixing 987. Code is complete now, needs some debugging still.