Untested, many minor improvements and fixes