fix bug  #11 and clean code