refactored quite a bit