Loop fix
Added shutdown hook