refactored a little more