Multiple fixes and cleanup

Individual patches contain more information