First working version
Improvements (but broken)