use reference where a null would be invalid and minor cleanup