Optimize commit

Analysis and refactoring the code