rework logic and clean up comments