Fix various small bugs in original implementation