Fix issues encountered by Tim Hang