fixed some errors + refactor code + comments