refactored to functions