snapshot: refactoring and toidying code