Several fixes

Improved checking to avoid null pointer exceptions
Better focus for editor