updated to be more efficient