clean up main path, move err handling to functions