Improvements and suggestiosn from @samikeijonen.