Added control for maximum tokens per ip address

And added some more unit tests