Fully working version (with bugs and todos)