Moved repetitive code to a custom library for easy inclusion with multiple mods