Variable fixes and null checks