Please review second implementation. Maybe this can be done more easily. Could you help me to implement this feature.