working nested code