general code refactoring and near full table coverage