refactoring and idiomatic changes