First working version, with tests