First working version, with some stuff to implement yet