Bug fix, code optimization