Index: libmpcdec/branches/zorg/src/decoder.h
===================================================================
--- libmpcdec/branches/zorg/src/decoder.h	(revision 107)
+++ libmpcdec/branches/zorg/src/decoder.h	(revision 108)
@@ -64,14 +64,14 @@
     /// @name internal state variables
     //@{
-	mpc_uint32_t  stream_version; ///< Streamversion of stream
-	mpc_uint32_t  max_band; ///< Maximum band-index used in stream (0...31)
-	mpc_uint32_t  ms; ///< Mid/side stereo (0: off, 1: on)
-	mpc_uint32_t  is_true_gapless; ///< True gapless? (0: no, 1: yes)
-	mpc_uint32_t  frames; ///< Number of frames in stream
-	mpc_uint32_t  last_frame_samples; ///< Number of valid samples within last frame
-	mpc_uint32_t channels; ///< Number of channels in stream
+	mpc_uint32_t stream_version;     ///< Streamversion of stream
+	mpc_uint32_t max_band;           ///< Maximum band-index used in stream (0...31)
+	mpc_uint32_t ms;                 ///< Mid/side stereo (0: off, 1: on)
+	mpc_uint32_t is_true_gapless;    ///< True gapless? (0: no, 1: yes)
+	mpc_uint32_t frames;             ///< Number of frames in stream
+	mpc_uint32_t last_frame_samples; ///< Number of valid samples within last frame
+	mpc_uint32_t channels;           ///< Number of channels in stream
 
-	mpc_uint32_t  samples_to_skip;
-	mpc_uint32_t  decoded_frames;
+	mpc_uint32_t samples_to_skip;    ///< Number samples to skip (used for seeking)
+	mpc_uint32_t decoded_frames;     ///< Number of frames decoded from file begining
 
     // randomizer state variables
Index: libmpcdec/branches/zorg/src/mpc_decoder.c
===================================================================
--- libmpcdec/branches/zorg/src/mpc_decoder.c	(revision 107)
+++ libmpcdec/branches/zorg/src/mpc_decoder.c	(revision 108)
@@ -119,7 +119,6 @@
 							  mpc_frame_info * i)
 {
-	d->decoded_frames++;
-
-	if (d->decoded_frames > d->frames && !d->is_true_gapless) {
+	mpc_int64_t samples_left;
+	if (d->decoded_frames >= d->frames && !d->is_true_gapless) {
 		mpc_decoder_reset_y(d);
 	} else {
@@ -129,18 +128,19 @@
 	mpc_decoder_synthese_filter_float(d, i->buffer);
 
+	d->decoded_frames++;
+
     // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
     // reconstruct exact filelength
-	if (d->decoded_frames == d->frames && (d->stream_version & 15) == 7) {
-		d->last_frame_samples = mpc_bits_read(r, 11);
-		if (d->last_frame_samples == 0) {
-            // Encoder bugfix
-			d->last_frame_samples = MPC_FRAME_LENGTH;
-		}
-	}
-
-	mpc_int32_t samples_left = d->last_frame_samples + MPC_DECODER_SYNTH_DELAY
-			+ (d->frames - d->decoded_frames) * MPC_FRAME_LENGTH;
+	if (d->decoded_frames == d->frames && (d->stream_version & 15) == 7 &&
+		(d->last_frame_samples = mpc_bits_read(r, 11)) == 0)
+		// Encoder bugfix
+		d->last_frame_samples = MPC_FRAME_LENGTH;
+
+	samples_left = d->last_frame_samples + MPC_DECODER_SYNTH_DELAY
+			+ ((mpc_int64_t)d->frames - d->decoded_frames) * MPC_FRAME_LENGTH;
 
 	i->samples = samples_left > MPC_FRAME_LENGTH ? MPC_FRAME_LENGTH : samples_left < 0 ? 0 : samples_left;
+
+	if (samples_left <= MPC_FRAME_LENGTH) d->is_true_gapless = 0;
 
 	if (d->samples_to_skip) {
Index: libmpcdec/branches/zorg/src/mpc_demux.c
===================================================================
--- libmpcdec/branches/zorg/src/mpc_demux.c	(revision 107)
+++ libmpcdec/branches/zorg/src/mpc_demux.c	(revision 108)
@@ -98,4 +98,6 @@
 	int err;
 
+	memset(&d->si, 0, sizeof d->si);
+
     // get header position
 	err = d->si.header_position = mpc_skip_id3v2(d->r);
@@ -106,5 +108,6 @@
 	if(!err) return MPC_STATUS_FILE;
 
-	memset(&d->si, 0, sizeof d->si);
+	d->si.tag_offset = d->si.total_file_length = d->r->get_size(d->r);
+
 	mpc_demux_fill(d, 4, 0);
 	magic[0] = mpc_bits_read(&d->bits_reader, 8);
