fix NPE?
Some more fixes
Toggle rewrite (1/2)

Change-Id: I80ef0c3f1cbe8e0d35c7a4e4111ad22b96196963