Improve replaceall function