fix bugs in previous patch