Fixed bug found by Hu Jekkay.