fixed image preview bugs, code cleaned