Updated to a more effective method