refactored this thing a bit