fixed issue and fixed size problem
fixed initialization
added boundary check