working code with settings