fixed some minor bug in the code