fix bugs in init function