optimize some code