fixed#1

fixed#1, and some code cleanup