added some safeguards for double initialization