adding some fixes that I noticed to get it working more reliably.