Proper implementation of scopes

First attempt on solving #7