general cleanup, got some new ideas from EmacsCrashCode