Add limit parameter to replace()

The implementation of that is somewhat ugly :)
Fix globals initialization

The handlers structure is now initialized In RINIT rather than GINIT.
sync master