A working version. Finally!