finally if statements works correctly