First complete working version (hopefully)