merge lestrrat's refactoring