Refactored snapshot code