Replaced repeating code with a library call