Added more comments and removed useless code