Robust solution to dim screen with AS?

I found this simple solution to dim the screen with AppleScript macbook pro - Dim screen brightness of MBP, using AppleScript (and while using a secondary monitor)? - Ask Different

I want to go all the way down and then up one step so I modified the suggested script to

tell application "System Events"
    repeat 16 times
        key code 109 -- darker
        --delay 1 --doesn't really help
    end repeat
--delay 5 --doesn't really help
key code 113 -- brighter
end tell

but the solution is not stable. Looping 16 times usually just goes approximately halfway and key code 113 regularly doesn’t seem to register at all. I have added delays, even long delays (5 seconds) but it still is unreliable, especially if you run it using Screen Sharing (in Script Editor).

I am on Catalina. Following works for me stably.
 

-- script: DIM THE DISPLAY
-- written: by KniazidisR, today

tell application "System Events"
	key down 63 -- holding Fn key
	repeat 16 times
		-- gradually decreaze the brightness to 0
		key code 145 -- to increaze, use 144
	end repeat
	key code 144 -- increaze the brightness 1 step back
	key up 63 -- release Fn key
end tell