refactored a bit.