refactored and made better, generally.