Improve error handling, and neaten rename functionality by using a regex.