added comments and debug
resort function call and debug output