optimised some return statements and flow