refactoring longest.c