refactored, a little cleaner