Updated Code to be more efficient