moved initialization inside fitting algorithm