Avoid early return
Use predicate method and eliminate local
Fix file descriptor leak