working version, with settings