refactored a little