refactored for betterness