Merged in bugfixes from shell merging code