Changed some coding style in order to make all function easy to understand