Test fixes and general cleanups