Some more fixes and cleanups. All tests pass now both in Chrome and cmd line