refactored a bit more