A working version, but it has performance problems