optimized the code

instead of another function call to logic. just make use of existing
query and check for not null