tidy, lint and additional error check