first pass bugfix and linting