Fixes screen off case.

Issue 842
This is the updated PR 848, rebased and addressed comments