adding pagination support and corrected snapshot write code