refactored so easier to work with