changed logic and add comments for later code