refactoring GET code to filter only valid results