Simplified overly complex function