refactored and added some things
still more work todo until final architecture becomes clear