Fixed some problems with the screen off timer

Most important: If the device was unlocked, the screen off timer was not stopped, if "on_unlock" was not set.
The other changes are more or less cosmetic. See commit messages for more info.