commented code thoroughly