More bug fixes and dead code elimination