Minor changes in algorithim