Simplify a bit this copy/pasted function