use preferences handler instead and some more minor improvements