modifications to handle null connection (unfinished)