Initialize and finalize functions