bug fix & clean up