Add more optimization; refactor; edit comments; remove unused code.