First working version. Includes tests