misc refactor&cleanup