Initialization code and utility functions