Fixed a crash when the address is invalid
Code cleanup