Refactoring PandaCal code to be more robust and clear.