refactored code and added delegate protocol to change hierarchy order and redraw