First working version

The first version that seems to work as intended