Re-wrote code