When using if, try, switch or other similar flow control mechanisms, always encapsulate the smallest block of code possible.
Line 31 to line 44 is exactly the same other then 1 function call.
So only put that function call in the if block.
This creates less code and you dont have to repeat your code again which is happening right now
This will help in debugging since if there is a bug, you will have to change it from only 1 place rather then multiple places.
Happy coding :)