move result assignment out of if-else block