minor corrections, NULL checks
minor refacts
Merge branch 'refact' into dev