Remove unused code and minor optimization