updating code to sort input properly and handle empty (size zero) files