updated answer and reorganized structure