Update code

Organization and optimization