Refactored multiple functions for simplicity