Redid the changes proposed earlier properly

Hey Ale,

It should be much cleaner now. I hope this time we don't merge conflicts ;)