fixed issue when converting int to char array. Refactored codes