fixed a small bug and changed code structure for accomplish the #69 issue