Almost working version, there is a problem with updating document.