refactored; much more sensible, MAYBE