Corrected logic for wrapping data when database allows and added guards ...

...to prevent wrapping when database does not allow. This resolves issue #86.