fixed problems with preview output and improved the controller