updated to improve performance