refactored and oojs code