fixed bugs in the original version