numerous errors fixed; refactored types for simplicity