Add perpetual code

@mortenvp @janusheide I will try to update this branch with the master. We should release perpetual NC soon.
I think that the wrap around case you ask for is already tested so I will just split the test to make it stand out, ok?