refactored a bit better