Readded changes made by @alexbennett.