Fixed some bugs with the init function.