optimize return logic