Various crucials and trivials bug fixes. It was a long night.