fix gcc compilation when using a reference type
Add unit tests