Improved initializing function.