A working version with bugs