bug fixes. thanks @leeping and peter