Factorize connection handling to pronsole
Fix slicing #511