threw in some null checks
some cleanup