improved logic, with night light function