null checks added where necessary