Refactor to add more reusable code