First (more or less) working version