Added preview window example
Fixed messy coding.