Refactor staff code into library