Fix linting errors and bugs