some cleanup; more debugging needed