refactored complicated things