Complex function broken down