final version without changing the onPreviewFrame
latest version! the onPreviewFrame bug seems to be fixed!