Improved the initialization function.