Fixed a few subtle bugs in custom initialization code