Some imporovements of code