wholly refactored *working*