optimize some functions