refactored to be much leaner