working version from REPL