code modified based on gnu warning flag -Wall