bug fix, more comments and removed useless variable