Optimize some codes