optimize some codes