Fixed preview logic and some code comments