code corrections, working version